import { wxRequest } from '../../utils/server.js';  
const _wxRequest = new wxRequest();
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgUrl: app.globalData.imgUrl,
     device:{ },
     typeIndex:0,
     deviceList:[], 
     uploadUrl: wx.getStorageSync('uploadUrl'), 
     chooseColor:[],
     checkAll: false,
    colorList:[
      {
        id:1,
        color:'#526164',
        name:'1%双氧'
      },
      {
        id:2,
        color:'#666666',
        name:'灰色'
      },{
        id:3,
        color:'#6b95f7',
        name:'蓝色'
      },{
        id:4,
        color:'#52edff',
        name:'12%双氧'
      },{
        id:5,
        color:'#663200',
        name:'棕色'
      },{
        id:6,
        color:'#ffc72c',
        name:'黄色'
      },{
        id:7,
        color:'#222222',
        name:'黑色'
      },{
        id:8,
        color:'#d7d5c6',
        name:'白色'
      },
       
      {
        id:9,
        color:'#ff5414',
        name:'红色'
      },
      {
        id:10,
        color:'#329900',
        name:'绿色'
      }
    ]
  },
  onShow(){
    this.getDeviceList()
  },


  getDeviceList: function() {
    var params = {
      keyword: this.data.keyword, 
      pageNo: 1,
      pageSize:999
    }
     
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/device/findList',
      method: 'POST',
      data:params
    }, (res) => {
      let list = res.list.map(item => {
        if(item.stoName) {
          item.note += ` - ${item.stoName}`;
        }

        if(item.stoCreateName) {
          item.note += ` - ${item.stoCreateName}`;
        }
        return item;
      });
      this.setData({
        deviceList: list, 
      });
    })
  },


  //单选
  checkColor:function(e){
    var id=e.currentTarget.dataset.id
    var chooseColor=this.data.chooseColor
    if(chooseColor.indexOf(id)>-1){
      var index=chooseColor.indexOf(id)
      chooseColor.splice(index,1)
    }else{
      chooseColor.push(id)
    }
    this.setData({
      chooseColor:chooseColor,
      checkAll:false
    })
  },

//设备检测
  chooseDyeRecord:function(){
  var params={
    recType:2,
    devId:this.data.deviceList[this.data.typeIndex].id
  }
    _wxRequest.wxTonkenAjax({
      url: app.globalData.apiUrl + '/gds/protected/dyeRecord/create',
      method: 'POST',
      data:params
    }, (res) => {
      wx.showToast({
        title: '检测成功',
      })
      console.log(res,'dyeRecord-----')
    })
  },

  checkboxChange:function(e){   
      if (e.detail.value[0] =='') {
        this.data.chooseColor=this.data.colorList.map(item=>item.id)
      }else{
        this.data.chooseColor=[]
      }
      this.setData({
        chooseColor:this.data.chooseColor
      })

  }


 
})